package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.domain.vo.ProductSkuBrandVo;
import com.spzx.product.api.domain.vo.SkuDetailVo;
import com.spzx.product.api.domain.vo.SkuSearchVo;
import com.spzx.product.api.RemoteSkuOrBrandService;
import com.spzx.product.api.domain.Brand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class RemoteSkuOrBrandFallbackFactory implements FallbackFactory<RemoteSkuOrBrandService> {
    @Override
    public RemoteSkuOrBrandService create(Throwable cause) {
        log.error("商品服务调用失败:{}", cause.getMessage());
        return new RemoteSkuOrBrandService() {
            @Override
            public R<ProductSkuBrandVo> getSkuOrBrand() {
                return R.fail("首页热门数据及一级分类服务调用失败:" + cause.getMessage());
            }

            @Override
            public R<TableDataInfo> getSkuList(SkuSearchVo skuSearchVo) {
                return R.fail("获取商品sku列表服务调用失败:" + cause.getMessage());
            }

            @Override
            public R<List<Brand>> getBrandAll() {
                return R.fail("获取商品品牌服务调用失败:" + cause.getMessage());
            }

            @Override
            public R<SkuDetailVo> getSkuDetail(Long skuId) {
                return R.fail("获取商品详情服务调用失败:" + cause.getMessage());
            }
        };
    }
}
